package com.wn.system.controller;

import com.wn.common.model.dto.bank.CardAddDTO;
import com.wn.common.model.dto.user.LoginDto;
import com.wn.common.model.dto.user.UserRegisterDto;
import com.wn.common.model.vo.bank.SignatureVo;
import com.wn.common.model.vo.user.LoginVo;
import com.wn.common.model.vo.user.TokenVo;
import com.wn.common.model.vo.user.UserInfoVo;
import com.wn.common.result.Result;
import com.wn.system.entity.User;
import com.wn.system.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2023-02-23
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;
    @PostMapping("register")
    public Result register(@RequestBody UserRegisterDto userRegisterDto) {

        userService.register(userRegisterDto);

        return Result.ok();
    }

    @PostMapping("login")
    public Result login(@RequestBody LoginDto loginDto) {
        LoginVo vo = userService.login(loginDto);
        return Result.ok(vo);
    }

    /**
     * auth 用户登录后才可以进行绑卡
     * 用户进行绑卡的时候 需要提交一些数据
     *
     * @return
     */
    @ApiOperation("创建托管账户")
    @PostMapping("/auth/bank/card/add")
    public  Result addBankAccount(@RequestBody CardAddDTO cardAddDTO, HttpServletRequest request){
        //进行绑卡的业务操作
        Result<SignatureVo> result = userService.createConsumer(cardAddDTO);
        return result;
    }

    @GetMapping("/find/{phone}")
    public UserInfoVo findUserById(@PathVariable("phone") String phone){

        UserInfoVo userInfoVo = userService.findUserById(phone);
        return  userInfoVo;
    }
}
